import process from 'process'

export class IParams {
    pipelineID!: number

    pipelineName!: string

    buildNumber?: number

    workSpace!: string

    projectDir!: string

    buildJobID!: number

    kubectlVersion!: string

    kind!: string

    name!: string

    containerName!: string

    insecureSkipTlsVerify!: boolean

    clusterType?: string

    rolloutTimeoutSeconds!: number

    namespace!: string

    image!: string
}

export function getParams(): IParams {
    let params = new IParams()
    params.pipelineID = Number(process.env.PIPELINE_ID)
    params.pipelineName = process.env.PIPELINE_NAME as string
    params.buildNumber = Number(process.env.BUILD_NUMBER)
    params.workSpace = process.env.WORK_SPACE as string
    params.projectDir = process.env.PROJECT_DIR as string
    params.buildJobID = Number(process.env.BUILD_JOB_ID)
    params.kubectlVersion = process.env.KUBECTL_VERSION ? process.env.KUBECTL_VERSION : 'v1.16.4'
    params.kind = process.env.KIND as string
    params.name = process.env.NAME as string
    params.containerName = process.env.CONTAINER_NAME as string
    params.insecureSkipTlsVerify = process.env.INSECURE_SKIP_TLS_VERIFY === 'true'
    params.rolloutTimeoutSeconds = process.env.ROLLOUT_TIMEOUT_SECONDS ? Number(process.env.ROLLOUT_TIMEOUT_SECONDS) : 600
    params.namespace = process.env.NAMESPACE ? process.env.NAMESPACE : 'default'
    params.image = process.env.IMAGE as string
    return params
}